﻿using System;
using System.Drawing;
using System.Windows.Forms;
using mRemoteNG.App;

namespace mRemoteNG.Tools
{
    public class MouseClickSimulator
    {
        public static void Click(Control controlToClick, Point currentMousePosition)
        {
            // Simulate a mouse event since one wasn't generated by Windows
            var clientMousePosition = controlToClick.PointToClient(currentMousePosition);
            var tempWLow = clientMousePosition.X;
            var tempWHigh = clientMousePosition.Y;
            NativeMethods.SendMessage(controlToClick.Handle, NativeMethods.WM_LBUTTONDOWN,
                                      (IntPtr)NativeMethods.MK_LBUTTON,
                                      (IntPtr)NativeMethods.MAKELPARAM(ref tempWLow, ref tempWHigh));
            clientMousePosition.X = tempWLow;
            clientMousePosition.Y = tempWHigh;
            controlToClick.Focus();
        }
    }
}